import 'package:cool_ui/cool_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_member/utils/Counter.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';

class StudentStates extends StatefulWidget {
  @override
  _StudentStateState createState() => _StudentStateState();
}

class _StudentStateState extends State<StudentStates> {
  Map map = {};

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, designSize: Size(375, 667), allowFontScaling: false);
    return Container(
      margin: EdgeInsets.only(right: 15),
      child: Provide<Counter>(builder: (context, chid, counter) {
        return CupertinoPopoverButton(
          child: Container(
            child: counter.listStu.length != 0
                ? _nameStatus(
                    map: map.length == 0 ? counter.listStu.first : map)
                : Container(
                    margin: EdgeInsets.only(right: 15),
                    child: Text("沒有學生"),
                  ),
          ),
          popoverBuild: (BuildContext context) {
            return CupertinoPopoverMenuList(
              children: counter.listStu
                  .map((e) => CupertinoPopoverMenuItem(
                        leading: Center(
                          child: Container(
                            width: 25,
                            height: 25,
                            decoration: BoxDecoration(
                                color: Color(e["color"]==null?0Xff72c0a4:e['color']),
                                borderRadius: BorderRadius.circular(50)),
                          ),
                        ),
                        child: Container(
                          child: Column(
                            children: [
                              Text(
                                e["name"],
                                style: TextStyle(
                                    color: Color(0Xff7B7B7B), fontSize: 14),
                              ),
                              Text(
                                e["state"],
                                style: TextStyle(
                                    color: Color(0Xff93BB24), fontSize: 14),
                              )
                            ],
                          ),
                        ),
                        onTap: () {
                          print(e);
                          setState(() => map = e);
                          Navigator.pop(context);
                          return true;
                        },
                      ))
                  .toList(),
            );
          },
        );
      }),
    );
  }

  /// 名字
  Widget _nameStatus({Map map}) {
    return Container(
      margin: EdgeInsets.only(bottom: 15),
      child: Row(
        children: [
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Container(
                child: Text(
                  map["name"],
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: Color(0XFFFFFFFF),
                    fontSize: ScreenUtil().setSp(12),
                    fontFamily: "SemiBold",
                  ),
                ),
              ),
              Container(
                child: Text(
                  map["state"],
                  style: TextStyle(
                    color: Color(0XffD7FFAC),
                    fontSize: ScreenUtil().setSp(12),
                    fontFamily: "SemiBold",
                  ),
                ),
              ),
            ],
          ),
          Container(
            width: 30,
            height: 30,
            margin: EdgeInsets.only(left: 10),
            decoration: BoxDecoration(
                color: Color(map["color"]),
                borderRadius: BorderRadius.circular(50)),
          )
        ],
      ),
    );
  }
}
